import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-11-17
 * Time: 17:08
 * To BE A Better Person-2020-3-2
 */
@WebServlet("/index")
public class indexservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf8");
        HttpSession session= req.getSession(false);
        if(session == null){
            resp.setHeader("Location","127.0.0.1:8080/CookieLogin/login.html");
            System.out.println("进来了");
            return;
        }
        String usernmae= (String) session.getAttribute("username");
        Integer time= (Integer) session.getAttribute("visittime");
        resp.getWriter().write("username:"+usernmae+"visitCount:"+time);
    }
}
